package com.itheima.web.controller.oms;

import com.itheima.result.AjaxResult;
import com.itheima.result.PageResult;
import com.itheima.service.oms.OmsOrderReturnApplyService;
import com.itheima.vo.oms.OmsOrderReturnApply;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单退货申请 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/returnApply")
public class OmsOrderReturnApplyController {

    @DubboReference
    private OmsOrderReturnApplyService orderReturnApplyService;

    /**
     * 分页查询退货申请
     */
    @GetMapping("/list")
    public AjaxResult list(String createTime,String handleMan,String handleTime,Integer id,
                           Integer pageNum,Integer pageSize,String receiverKeyword,Integer status) {
        PageResult result = orderReturnApplyService.listPage(createTime, handleMan, handleTime, id,
                pageNum, pageSize, receiverKeyword,status);
        return AjaxResult.success(result);
    }

    /**
     * 获取退货申请详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getOrderReturn(@PathVariable Integer id) {
        OmsOrderReturnApply returnApply = orderReturnApplyService.getById(id);
        return AjaxResult.success(returnApply);
    }

    /**
     * 修改退货申请状态
     *
     * @param id
     * @param orderReturnApply
     * @return
     */
    @PostMapping("/update/status/{id}")
    public AjaxResult updateStatus(@PathVariable Integer id, @RequestBody OmsOrderReturnApply orderReturnApply) {
        Boolean count = orderReturnApplyService.updateStatus(id, orderReturnApply);
        if (count) {
            return AjaxResult.success("修改成功");

        }
        return AjaxResult.error("修改失败");
    }

    /**
     * 批量删除退货申请
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestParam List<Long> ids) {
        Boolean count = orderReturnApplyService.removeByIds(ids);
        if (count) {
            return AjaxResult.success("修改成功");
        }
        return AjaxResult.error("修改失败");

    }
}